package org.feidao.chapter65.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;
/**
 * Created by linghufeixia on 2022-12-28.
 * header config
 */
@Configuration
public class HeadersConfig {

    @Bean("headers_exchange")
    public HeadersExchange headersExchange() {
        return ExchangeBuilder.headersExchange("headers_exchange").durable(true).build();
    }

    @Bean("headers_queue_A")
    public Queue headerQueueA(){
        return QueueBuilder.durable("headers_queue_A").build();
    }

    @Bean
    public Binding headersBindA(){
        Map<String,Object> headerValues = new HashMap<>();
        headerValues.put("type", "gass");
        headerValues.put("data", "realTime");
        return BindingBuilder.bind(headerQueueA()).to(headersExchange()).whereAll(headerValues).match();
    }

    @Bean("headers_queue_B")
    public Queue headerQueueB(){
        return QueueBuilder.durable("headers_queue_B").build();
    }

    @Bean
    public Binding headersBindB(){
        Map<String,Object> headerValues = new HashMap<>();
        headerValues.put("type", "gass");
        headerValues.put("data", "realTime");
        return BindingBuilder.bind(headerQueueB()).to(headersExchange()).whereAny(headerValues).match();
    }
}
